// 封装分类数据业务相关代码

import {useRoute} from "vue-router";
import {getCategoryAPI} from '@/apis/category.js'
import {onMounted,ref} from 'vue';
import {onBeforeRouteUpdate} from "vue-router";
export const useCategory = () => {
    //获取数据
    const categoryData=ref({})
    const route=useRoute()
    const getCategory=async(id=route.params.id)=>{
        const res= await getCategoryAPI(id)
        categoryData.value=res.result
    }
    onMounted(()=>{
        getCategory()
    })
    onBeforeRouteUpdate((to)=>{
        console.log('路由变化了')
        console.log(to)
        getCategory(to.params.id)
    })
    return{
        categoryData
    }
}